<template>
	<view>

		<view class="top">根据子女年龄和教育预期花费，为您定制教育理财规划</view>
		<view class="box">
			<view class="row">
				<view class="row-left">子女年龄</view>
				<view class="row-right"><input type="text" placeholder="请输入子女年龄" /> 岁</view>
			</view>
			<view class="row">
				<view class="row-left">幼儿园目标金额</view>
				<view class="row-right">
					<uni-number-box></uni-number-box>
				</view>
			</view>
			<view class="row">
				<view class="row-left">小学目标金额</view>
				<view class="row-right">
					<uni-number-box></uni-number-box>
				</view>
			</view>
			<view class="row">
				<view class="row-left">初中目标金额</view>
				<view class="row-right">
					<uni-number-box></uni-number-box>
				</view>
			</view>
			<view class="row">
				<view class="row-left">高中目标金额</view>
				<view class="row-right">
					<uni-number-box></uni-number-box>
				</view>
			</view>
			<view class="row">
				<view class="row-left">大学目标金额</view>
				<view class="row-right">
					<uni-number-box></uni-number-box>
				</view>
			</view>
			<view class="row">
				<view class="row-left">创业基金</view>
				<view class="row-right">
					<uni-number-box></uni-number-box>
				</view>
			</view>
		</view>
		<view class="canvas-box">
			<view class="canvas-box-top">现在需要获取的</view>
			<view class="canvas-box-sec">
				<view class="left">
					<view class="left-top">投资金额</view>
					<view class="left-bot"><label class="number">3500</label>元</view>
				</view>
				<view class="left">
					<view class="left-top">模拟历史业绩</view>
					<view class="left-bot"><label class="number">7.2</label>%</view>
				</view>
			</view>
			<view class="container">


				<view class="canvasView">
					<view class="canvas-bar">
						<view class="tuijian">推荐资产组合</view>
					</view>
					<mpvue-echarts :echarts="echarts" :onInit="pieInit" canvasId="pie" ref="pieChart" />
				</view>
				<view class="canvasView">
					<view class="canvas-bar">
						<view class="tuijian">教育金预计年支出</view>
					</view>

					<mpvue-echarts :echarts="echarts" :onInit="barInit" canvasId="bar" ref="barChart" />
				</view>
				<view>
					从2018年*月开始投资3500元至****年*月，共投入金额****元，到20**共支出****元。
				</view>
				<view class="tishi">* 根据模拟历史数据计算，不代表未来业绩，投资需谨慎。</view>
			</view>

		</view>
	</view>
	</view>
</template>

<script>
	import uniNumberBox from "@/components/uni-number-box.vue";
	import * as echarts from '@/components/echarts/echarts.simple.min.js';
	import mpvueEcharts from '@/components/mpvue-echarts/src/echarts.vue';
	const cityList = [{
				value: 25,
				name: '浮动收益 25%'
			}, {
				value: 10,
				name: '保险保障 10%'
			}, {
				value: 15,
				name: '流动性资产 15%'
			}, {
				value: 10,
				name: '风险对冲资产 10%'
			}, {
				value: 20,
				name: '固定收益 20%'
			}];
		let pieOption = {
		animation: false,
		backgroundColor: '',
		color: ['#d0ac6d', '#fd5c11', '#488aff', '#1bd38b', '#8350f5', '#FF9F7F'],
		series: [{
			label: {
				normal: {
					fontSize: 14
				}
			},
			type: 'pie',
			center: ['50%', '50%'],
			radius: ['40%', '70%'],
			data: [],
			itemStyle: {
				emphasis: {
					shadowBlur: 10,
					shadowOffsetX: 0,
					shadowColor: 'rgba(0, 2, 2, 0.3)'
				}
			}
		}]
	};


	let barOption = {
		animation: true,
		color: ['#f6b200', '#7f4ff5', '#fe6e17', '#37affe', '#fe6a15', '#ff682d'],
		grid: {
			x: 35,
			x2: 10,
			y: 30,
			y2: 25
		},
		calculable: false,
		xAxis: [{
			type: 'category',
			data: ['2010', '2011', '2012', '2013', '2014', '2015', '2016', '2017', '2018']
		}],
		yAxis: [{
			type: 'value',
			splitArea: {
				show: true
			}
		}],
		series: [{

			name: '',
			type: 'bar',
			data: [6302, 6881, 3208, 5109, 10222, 3455, 6881, 3208, 5109],
			itemStyle: {
				/* normal: {
					 color: new echarts.graphic.bararGradient(0, 0, 0, 1, [{
                            offset: 0,
                            color: '#7ea8ee'
                        }, {
                            offset: 1,
                            color: '#5d87f4'
                        }])
				} */

			}
		}]
	};

	 
	export default {
		components: {
			uniNumberBox,
			mpvueEcharts
		},

		data() {
			return {
				echarts: echarts,
				updateStatus: false
			};
		},
		onLoad() {
			pieOption.series[0].data = cityList.slice(0);
			console.log(pieOption)
		},
		methods: {
			updatePie() {
				// 参考 mpvue-charts 的懒加载示例
				// https://github.com/F-loat/mpvue-echarts/blob/master/examples/lazyLoad.vue

				if (this.updateStatus) {
					return;
				}
				pieOption.series[0].data.push({
					value: 20,
					name: '武汉'
				});
				pieOption.series[0].data.push({
					value: 10,
					name: '杭州'
				});
				this.$refs.pieChart.init();
				this.updateStatus = true;
			},
			pieInit(canvas, width, height) {
				let pieChart = echarts.init(canvas, null, {
					width: width,
					height: height
				})
				canvas.setChart(pieChart)
			
				pieChart.setOption(pieOption)
				return pieChart
			},
			barInit(canvas, width, height) {
				let barChart = echarts.init(canvas, null, {
					width: width,
					height: height
				})
				canvas.setChart(barChart)

				barChart.setOption(barOption)
				return barChart
			}
		}
	}
</script>

<style>
	.top {
		line-height: 35px;
		padding-left: 19upx;
		font-size: 12px;
		font-weight: 500;
		color: rgba(153, 153, 153, 1);
	}

	.box {
		padding: 0 30upx;
		background: rgb(255, 255, 255);
	}

	.row {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;
		height: 54px;
		border-bottom: 1px solid rgba(0, 0, 0, 0.1);

	}

	.row-left {
		font-size: 15px;
		font-weight: 500;
		color: rgba(51, 51, 51, 1);
	}

	.row-right {
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		align-items: center;

	}

	.canvas-box {
		padding: 25px 30upx 0;
		background: rgb(255, 255, 255);
	}

	.canvas-box-top {
		text-indent: 10px;
		font-size: 17px;
		font-weight: bold;
		color: rgba(51, 51, 51, 1);
		border-left: 4px solid rgba(203, 147, 89, 1);

	}

	.canvas-box-sec {
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-around;
		height: 84px;
	}

	.left-top {
		font-size: 12px;
		font-weight: 500;
		color: rgba(153, 153, 153, 1);
	}

	.left-bot .number {
		font-size: 26px;
		font-weight: bold;
		color: rgba(68, 68, 68, 1);
	}

	.page-section-title {
		width: 690upx;
		flex-direction: row;
		justify-content: space-between;
		height: 55px;
		align-items: center;
		border-bottom: 1px solid rgba(238, 238, 238, 1);

	}

	.title {
		font-size: 17px;

		font-weight: bold;
		color: #444444;
		border-left: 4px solid rgba(203, 147, 89, 1);
		text-indent: 10px;
	}

	.btn {
		border: 1px solid rgba(196, 156, 90, 1);
		border-radius: 20px;
		color: rgba(196, 156, 90, 1);
		padding: 3px 10px;
		font-size: 12px
	}

	.container {
		width: 100%;
		padding: 0 30upx 30upx;
		box-sizing: border-box;

	}

	.container,
	.canvasView {
		width: 100%;
		flex: 1;
		flex-direction: column;
	}

	.canvasView canvas {
		height: 400upx;
	}

	.navigate {
		color: #007AFF;
	}

	.canvas-bar {
		display: flex;
		flex-direction: row;
		justify-content: center;
		height: 55px;
		align-items: center;
	}

	.tuijian {
		font-size: 16px;

		font-weight: bold;
		color: rgba(51, 51, 51, 1);
	}
	
	.tishi {
		font-size: 12px;
		font-weight: 500;
		color: rgba(153, 153, 153, 1);
		margin-top: 32px;
	}
</style>
